package com.dingding.web.mall.action;

import java.util.List;

import com.dingding.facade.mall.dto.CommodityInfoRes;
import com.dingding.facade.mall.dto.UserCommodityOrderDTO;
import com.dingding.facade.mall.dto.UserIntegraDetailRecordRes;
import com.dingding.facade.mall.dto.UserMallIndexRes;
import com.dingding.web.base.action.BaseAction;

/**
 * @Description: 用户商城action
 * @author fengshuonan
 * @date 2016年3月23日 下午3:23:19
 */
@SuppressWarnings("serial")
public class UserMallAction extends BaseAction {

	/**
	 * @Description: 获取商城首页数据
	 * @author fengshuonan
	 */
	public String getMallIndex() {

		// 获取用户ID
		String userId = super.getPara("userId");

		log.info("userId=" + userId + ",userMallFacade = " + userMallFacade);

		// 获取该用户的商城首页信息
		UserMallIndexRes indexRes = this.userMallFacade.getMallIndexInfo(userId);

		// 把返回信息封装为json
		String jsonp = super.getResJsonp(indexRes);

		super.write(jsonp);

		return NONE;
	}

	/**
	 * 
	 * @Description: 购买商品
	 * @author fengshuonan
	 * @return String
	 * 
	 */
	public String buyItem() {

		// 获取用户ID
		String userId = super.getPara("userId");
		// 商品ID
		String itemId = super.getPara("commodityId");

		// 执行用户购买服务，返回状态码
		int code = this.userMallFacade.buyItem(userId, itemId);
		String jsonp = super.generateResponseData(code, null);

		super.write(jsonp);
		return NONE;
	}

	/**
	 * 
	 * @Title: getCommodityOrderList
	 * @Description:获取用户商品订单列表
	 * @author zhouxuan
	 * 
	 * 
	 */
	public String getCommodityOrderList() {

		// 获取用户id获得用户订单列表
		String userId = super.getPara("userId");

		List<UserCommodityOrderDTO> userCommodityOrderDTOs = this.userMallFacade.getUserCommodityOrderList(userId);

		// 封装返回值信息
		String json = super.getResJsonp(userCommodityOrderDTOs);

		super.write(json);

		return NONE;
	}

	/**
	 * 
	 * @Title: getCommodityInfo
	 * @Description:获取商品详情
	 * @author zhouxuan
	 * 
	 */
	public String getCommodityInfo() {

		// 获取商品id
		String commodityId = super.getPara("commodityId");

		// 根据id获取商品详情
		CommodityInfoRes commodityInfoRes = this.userMallFacade.getCommodityInfoRes(commodityId);

		// 封装返回值信息
		String json = super.getResJsonp(commodityInfoRes);

		super.write(json);

		return NONE;
	}
	/**
	 * @Title: getUserIntegralList
	 * @Description: 获取用户积分列表
	 * @author zhouxuan
	 */
	public String getUserIntegralList() {
		// 获取用户id
		String userId = super.getPara("userId");
		// 获取分页参数
		String row = super.getPara("row");
		// 获取单页个数
		String pageSize = super.getPara("pageSize");
		// 获取返回信息
		List<UserIntegraDetailRecordRes> userIntegraDetailRecordRe = this.userMallFacade
				.getUserIntegraDetailRecordList(userId, Integer.parseInt(row), Integer.parseInt(pageSize));
		//将返回信息封装为json
		String json = super.getResJsonp(userIntegraDetailRecordRe);
		
		super.write(json);
		
		return NONE;
	}

}
